package com.xiaodimall.backsys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaodimall.backsys.common.JsonResult;
import com.xiaodimall.backsys.mapper.AdminOrderMapper;
import com.xiaodimall.backsys.pojo.Order;
import com.xiaodimall.backsys.service.AdminOrderService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:
 * @Date: Created in 2022/12/1 17:59
 * @Description:
 */
@Service
public class AdminOrderServiceImpl implements AdminOrderService {

    @Resource
    AdminOrderMapper adminOrderMapper;

    @Override
    public List<Order> getAllOrder() {
        List<Order> orders = adminOrderMapper.selectList(new QueryWrapper<>());
        for (Order order : orders) {
            order.setOrderGoods(adminOrderMapper.selectOrderGoodsList(order.getOrderId()));
        }
        return orders;
    }

    @Override
    public JsonResult updateOrder(Integer orderId, Integer totalPrice, String userAddress) {
        Order order = adminOrderMapper.selectOne(new QueryWrapper<Order>().eq("order_id", orderId));
        order.setTotalPrice(totalPrice).setUserAddress(userAddress);
        int i = adminOrderMapper.updateById(order);
        if (i == 1 || i==0){
            return new JsonResult(200,"操作成功");
        }
        return new JsonResult(201,"失败");
    }
}
